package com.baidu.foody.ui.fragment

import android.app.Dialog
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.navigation.fragment.findNavController
import com.baidu.foody.R
import com.baidu.foody.databinding.FragmentBottomSheetDialogBinding
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.chip.Chip


class BottomSheetDialogFragment : BottomSheetDialogFragment() {
    private lateinit var mBinding: FragmentBottomSheetDialogBinding
    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        mBinding = FragmentBottomSheetDialogBinding.inflate(layoutInflater)
        initEvent()
        val dialog = BottomSheetDialog(requireContext())
        dialog.setContentView(mBinding.root)
        return dialog
    }

    private fun initEvent(){
        mBinding.searchBtn.setOnClickListener {
            //获取mealType
            val id = mBinding.mealChipGroup.checkedChipId
            val chip =  mBinding.mealChipGroup.findViewById<Chip>(id)
            val mealType = chip.text.toString()
            //获取DietType

            val dietType = mBinding.dietChipGroup
                .findViewById<Chip>(mBinding.dietChipGroup.checkedChipId)
                .text.toString()


            val directions = BottomSheetDialogFragmentDirections
                .actionBottomSheetDialogFragmentToRecipeFragment(mealType,dietType,true)
            findNavController().navigate(directions)
        }
    }
}